print("202509260954")
if not game:IsLoaded() then
    game.Loaded:Wait()
end

local replicated_storage = game:GetService("ReplicatedStorage")
local local_player = game:GetService("Players").LocalPlayer
local workspace = game:GetService("Workspace")

-- 日志函数
local log = function(s)
    local logMessage = string.format("[%s] %s", os.date("%Y-%m-%d %H:%M:%S"), tostring(s))

    -- 记录到本地文件
    local success, err = pcall(function()
        appendfile("log.txt", logMessage .. "\n")
    end)
    if not success then
        writefile("log.txt", logMessage .. "\n")
    end
end

-- 查找与礼物相关的对象
local function findGiftRelatedObjects()
    log("=== 查找与礼物相关的对象 ===")

    -- 检查ReplicatedStorage中的Gift相关对象
    local giftModule = replicated_storage:FindFirstChild("Gift_Module")
    if giftModule then
        log("找到Gift_Module: " .. giftModule.Name)

        -- 列出Gift_Module的所有子对象
        for _, child in ipairs(giftModule:GetChildren()) do
            log("  - " .. child.Name .. " (" .. child.ClassName .. ")")
        end
    end

    -- 检查ReplicatedStorage中的Gift文件夹
    local giftFolder = replicated_storage:FindFirstChild("Gift")
    if giftFolder then
        log("找到Gift文件夹: " .. giftFolder.Name)

        -- 列出Gift文件夹的所有子对象
        for _, child in ipairs(giftFolder:GetChildren()) do
            log("  - " .. child.Name .. " (" .. child.ClassName .. ")")

            -- 如果是容器，列出其内容
            if child:IsA("Folder") or child:IsA("Model") then
                for _, subchild in ipairs(child:GetChildren()) do
                    log("    - " .. subchild.Name .. " (" .. subchild.ClassName .. ")")
                end
            end
        end
    end

    -- 检查Remotes中的礼物相关远程事件
    local remotes = replicated_storage:FindFirstChild("Remotes")
    if remotes then
        for _, remote in ipairs(remotes:GetChildren()) do
            if remote.Name:match("Gift") or remote.Name:match("Present") then
                log("找到礼物相关的远程事件: " .. remote.Name .. " (" .. remote.ClassName .. ")")
            end
        end
    end

    -- 检查GameEvents中的礼物相关事件
    local gameEvents = replicated_storage:FindFirstChild("GameEvents")
    if gameEvents then
        for _, event in ipairs(gameEvents:GetChildren()) do
            if event.Name:match("Gift") or event.Name:match("Present") then
                log("找到礼物相关的事件: " .. event.Name .. " (" .. event.ClassName .. ")")
            end
        end
    end
end

-- 尝试调用可能的礼物相关远程函数
local function tryGiftRemotes()
    log("=== 尝试调用可能的礼物相关远程函数 ===")

    -- 查找所有可能的礼物远程函数
    local remotes = replicated_storage:FindFirstChild("Remotes")
    if remotes then
        for _, remote in ipairs(remotes:GetChildren()) do
            if remote.Name:match("Gift") or remote.Name:match("Present") then
                log("尝试调用: " .. remote.Name)

                -- 尝试不带参数调用
                pcall(function()
                    local result = remote:InvokeServer()
                    log("  调用结果: " .. tostring(result))
                end)

                -- 尝试带玩家参数调用
                if game.Players:GetPlayers()[1] then
                    pcall(function()
                        local targetPlayer = game.Players:GetPlayers()[1]
                        local result = remote:InvokeServer(targetPlayer)
                        log("  调用结果(带玩家参数): " .. tostring(result))
                    end)
                end

                -- 尝试带物品ID参数调用
                pcall(function()
                    local result = remote:InvokeServer(12345) -- 假设的物品ID
                    log("  调用结果(带物品ID): " .. tostring(result))
                end)
            end
        end
    end
end

-- 查找宠物礼物相关功能
local function findPetGiftFunctions()
    log("=== 查找宠物礼物相关功能 ===")

    -- 查找宠物礼物相关远程事件
    local gameEvents = replicated_storage:FindFirstChild("GameEvents")
    if gameEvents then
        -- 查找GiftPet
        local giftPet = gameEvents:FindFirstChild("GiftPet")
        if giftPet then
            log("找到GiftPet远程事件")

            -- 尝试调用GiftPet
            if game.Players:GetPlayers()[1] then
                local targetPlayer = game.Players:GetPlayers()[1]
                pcall(function()
                    giftPet:FireServer(targetPlayer)
                    log("已向 " .. targetPlayer.Name .. " 发送宠物礼物")
                end)
            end
        end

        -- 查找AcceptPetGift
        local acceptPetGift = gameEvents:FindFirstChild("AcceptPetGift")
        if acceptPetGift then
            log("找到AcceptPetGift远程事件")

            -- 尝试调用AcceptPetGift
            pcall(function()
                acceptPetGift:FireServer()
                log("已接受宠物礼物")
            end)
        end

        -- 查找PetGiftingService
        local petGiftingService = gameEvents:FindFirstChild("PetGiftingService")
        if petGiftingService then
            log("找到PetGiftingService远程事件")

            -- 尝试调用PetGiftingService
            if game.Players:GetPlayers()[1] then
                local targetPlayer = game.Players:GetPlayers()[1]
                pcall(function()
                    petGiftingService:FireServer(targetPlayer)
                    log("已向 " .. targetPlayer.Name .. " 发送宠物礼物服务")
                end)
            end
        end

        -- 查找FriendGiftEvent
        local friendGiftEvent = gameEvents:FindFirstChild("FriendGiftEvent")
        if friendGiftEvent then
            log("找到FriendGiftEvent远程事件")

            -- 尝试调用FriendGiftEvent
            if game.Players:GetPlayers()[1] then
                local targetPlayer = game.Players:GetPlayers()[1]
                pcall(function()
                    friendGiftEvent:FireServer(targetPlayer)
                    log("已向 " .. targetPlayer.Name .. " 发送好友礼物")
                end)
            end
        end
    end
end

-- 检查玩家背包中的礼物物品
local function checkForGiftItems()
    log("=== 检查玩家背包中的礼物物品 ===")

    local backpack = local_player:FindFirstChild("Backpack")
    if backpack then
        for _, item in ipairs(backpack:GetChildren()) do
            if item.Name:match("Gift") or item.Name:match("Present") then
                log("在背包中发现可能的礼物物品: " .. item.Name)

                -- 尝试使用该物品
                pcall(function()
                    if item:IsA("Tool") then
                        item.Parent = workspace -- 尝试将工具放置到工作区
                        log("已尝试使用礼物物品: " .. item.Name)
                    end
                end)
            end
        end
    end
end

-- 主函数
local function main()
    log("开始测试礼物功能")

    -- 查找礼物相关对象
    findGiftRelatedObjects()

    -- 尝试调用礼物相关远程函数
    tryGiftRemotes()

    -- 查找宠物礼物相关功能
    findPetGiftFunctions()

    -- 检查玩家背包中的礼物物品
    checkForGiftItems()

    log("礼物功能测试完成")
end

-- 执行主函数
main()
